import 'package:flutter/material.dart';
import 'package:wymusic/Util/request.dart';
import 'package:wymusic/widgets/songCard.dart';
import 'package:wymusic/widgets/swiper.dart';
import '../Util/EUMNoScrollBehavior.dart';

class Home extends StatefulWidget {
  Home({Key? key, this.player}) : super(key: key);
  final player;
  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  List<String> imgList = [];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // print('音乐');
    Api.getBanner({}).then((res) {
      // print(res);
      List<String> list = [];
      print(res);
      print(res['banners']);
      res['banners'].map((val) {
        // list.add(val['imageUrl'].toString());
        print(val['imageUrl']);
        list.add(val['imageUrl'].toString());
        return val['imageUrl'].toString();
      }).toList();
      // print(list);
      setState(() {
        imgList = list;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Color.fromARGB(255, 192, 0, 0),
          title: Row(
            children: const [
              Expanded(
                child: TabBar(
                  tabs: <Widget>[
                    Tab(text: "每日推荐"),
                    Tab(text: "搜索歌曲"),
                  ],
                ),
              )
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            ListView(
              children: <Widget>[
                Column(
                  children: [
                    Container(
                      child: ScrollConfiguration(
                        behavior: EUMNoScrollBehavior(),
                        child: ListView(
                          children: [
                            MySwiper(
                              imgList: imgList,
                            ),
                            AudioCard(
                              title: '七里香',
                              name: '周杰伦',
                              image:
                                  'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-479328cb-417a-467c-9512-83793cb72c1e/06fc01b6-b765-4155-a460-e66a8e2d4c40.webp',
                              backgroundColor:
                                  const Color.fromARGB(0, 255, 255, 255),
                              onTap: () {
                                widget.player.setUrl(
                                    'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-479328cb-417a-467c-9512-83793cb72c1e/4c2de51a-a381-4766-ab9d-c6db34f08a7c.flac');
                              },
                            ),
                          ],
                        ),
                      ),
                      height: 500,
                    ),
                  ],
                )
              ],
            ),
            ListView(
              children: const <Widget>[
                Text('2Tab'),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
